//
//  NewsCell.m
//  Cunli
//
//  Created by lilubin on 15/6/11.
//  Copyright (c) 2015年 lilubin. All rights reserved.
//

#import "NewsCell.h"
#import "NewsModel_yy.h"
#import "SearchInfoModel.h"
#import "UIImageView+WebCache.h"
#import "DeviceInfoClass.h"

@implementation NewsCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    /*
    switch ([DeviceInfoClass getCurrentDeviceDetailVersion]) {
        case DeviceInfoVersioniPhone4sOr5s:
            NSLog(@"4s or 5s");
            break;
        case DeviceInfoVersioniPhone6:
            NSLog(@"iphone6");
            break;
        case DeviceInfoVersioniPhone6p:
            NSLog(@"iphone6plus");
            break;
        default:
            NSLog(@"other device");
            break;
    }
     */
    
    if (_cellType == NewsCellSearch) {
        NSURL *picURL = [NSURL URLWithString:_searchNewsModel.pic];
        
        [_titleImgView setImageWithURL:picURL placeholderImage:[UIImage imageNamed:@"default_news"]];
        
        _titleLabel.text = _searchNewsModel.title;
        [_titleLabel setTextColor:[UIColor colorWithHexString:InfoCellTitleColorValue]];
        //        [_titleLabel setFont:[UIFont fontWithName:@"Heiti SC" size:17]];
        
        _introduceLabel.text = _searchNewsModel.introduce;
        [_introduceLabel setTextColor:[UIColor colorWithHexString:InfoCellIntroduceColorValue]];
        //        [_introduceLabel setFont:[UIFont fontWithName:@"Heiti SC" size:14]];
        return;
    }
    
    NSURL *picURL = [NSURL URLWithString:_newsModel.picURLStr];
    
    [_titleImgView setImageWithURL:picURL placeholderImage:[UIImage imageNamed:@"default_news"]];
    
    _titleLabel.text = _newsModel.title;
    [_titleLabel setTextColor:[UIColor colorWithHexString:InfoCellTitleColorValue]];
    //    [_titleLabel setFont:[UIFont fontWithName:@"Heiti SC" size:18]];
    [_titleLabel setFont:[UIFont systemFontOfSize:18.0f]];
    _introduceLabel.text = _newsModel.introduce;
    [_introduceLabel setTextColor:[UIColor colorWithHexString:InfoCellIntroduceColorValue]];
    //    [_introduceLabel setFont:[UIFont fontWithName:@"Heiti SC" size:14]];
    [_introduceLabel setFont:[UIFont systemFontOfSize:14.0f]];
    
    if ([DeviceInfoClass getCurrentDeviceDetailVersion] == DeviceInfoVersioniPhone4s || [DeviceInfoClass getCurrentDeviceDetailVersion] == DeviceInfoVersioniPhone5s) {
        [_titleLabel setFont:[UIFont systemFontOfSize:16.0f]];
        [_introduceLabel setFont:[UIFont systemFontOfSize:13.0f]];
    }
}

- (void)setNewsModel:(NewsModel_yy *)newsModel
{
    _newsModel = newsModel;
    
    NSURL *imgURL = [NSURL URLWithString:newsModel.picURLStr];
    [_titleImgView setImageWithURL:imgURL placeholderImage:[UIImage imageNamed:@"default_news"]];
    _titleLabel.text = _newsModel.title;
    _introduceLabel.text = _newsModel.introduce;
}

- (void)setSearchNewsModel:(SearchInfoModel *)searchNewsModel
{
    _searchNewsModel = searchNewsModel;
    
    NSURL *picURL = [NSURL URLWithString:_searchNewsModel.pic];
    [_titleImgView setImageWithURL:picURL placeholderImage:[UIImage imageNamed:@"default_news"]];
    _titleLabel.text = _searchNewsModel.title;
    _introduceLabel.text = _searchNewsModel.introduce;
}

@end
